﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    /// <summary>
    /// 离散点有关的设置
    /// </summary>
    public class PG17:Group
    {


        /// <summary>
        /// 离散点的个数
        /// </summary>
        int m_NREC = 0;

        /// <summary>
        /// 离散点的个数
        /// </summary>
        public int NREC
        {
            get { return m_NREC; }
            set { m_NREC = value; }
        }
        /// <summary>
        /// 离散点位置信息
        /// </summary>
        List<Receptor> m_Rec = new List<Receptor>();

        public List<Receptor> Rec
        {
            get { return m_Rec; }
            // set { m_Rec = value; }
        }





        public override string WriteToGroup()
        {
            string Subgroup = "", TempStr;

            TempStr = StrWriter.GetCLine();
            TempStr += "INPUT GROUPS: 17a & 17b -- Non-gridded (discrete) receptor information" + "\r\n";
            Subgroup += TempStr;

            TempStr = StrWriter.GetCLine();
            Subgroup += TempStr;

            TempStr = "! NREC = " + NREC.ToString() + " !" + "\r\n";
            Subgroup += TempStr;


            Subgroup += "!END!" + "\r\n";


            if (this.Rec.Count > 0)
            {
                for (int i = 0; i < this.Rec.Count; i++)
                {
                    TempStr = "";
                    //TempStr += "   " + i + 1 + "! X  =    " + Rec[i].Number.ToString() + ",   " + Rec[i].X.ToString() + ",   " + Rec[i].Y.ToString() + ",   " + Rec[i].Elevation.ToString() + ",   " + Rec[i].Height.ToString();
                    TempStr += "   " + (i + 1).ToString() + "! X  =    " + Math.Round(Rec[i].X, 5).ToString() + ",   " + Math.Round(Rec[i].Y, 5).ToString() + ",   " + Math.Round(Rec[i].Elevation, 3).ToString() + ",   " + Math.Round(Rec[i].Height, 3).ToString();


                    TempStr += "  !" + "   ! END !" + "\r\n";
                    Subgroup += TempStr;
                }

            }

            return Subgroup;
        }

        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {
                if (m_dic.Key == "NREC")
                {
                    this.NREC = Convert.ToInt32(m_dic.Value);
                }



                Receptor ps = new Receptor();
                List<double> lst = new List<double>();


                if (m_dic.Key == "X")
                {
                    int i = 0;
                    i += 1;
                    lst = StrWriter.ReturnDouList(m_dic.Value);
                    ps.Number = i;// Convert.ToInt32(lst[0]);
                    ps.X = lst[0];
                    ps.Y = lst[21];

                    ps.Elevation = lst[2];
                    ps.Height = lst[3];





                }

                Rec.Add(ps);


            }

        }
    }


    /// <summary>
    /// 离散点位置信息
    /// </summary>
    [Serializable]
    public class Receptor : ICloneable
    {


        /// <summary>
        /// 这个貌似没用
        /// </summary>
        int m_Number;

        public int Number
        {
            get { return m_Number; }
            set { m_Number = value; }
        }


        private int m_Sid = 0;
        /// <summary>
        ///　编号记录器，只增加，不减少以避免重复，且唯一.
        /// </summary>
        public int Sid
        {
            get { return m_Sid; }
            set { m_Sid = value; }
        }


        private string m_Name = "D";
        /// <summary>
        /// 名称，非Inp文件标识号  ID
        /// </summary>
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        private string m_DName = "接受点";
        /// <summary>
        /// 接受点名称
        /// </summary>
        public string DName
        {
            get { return m_DName; }
            set { m_DName = value; }
        }
        /// <summary>
        /// X坐标，km
        /// </summary>
        double m_X;
        /// <summary>
        /// X坐标，km
        /// </summary>
        public double X
        {
            get { return m_X; }
            set { m_X = value; }
        }
        /// <summary>
        /// Y坐标，km
        /// </summary>
        double m_Y;
        /// <summary>
        /// Y坐标，km
        /// </summary>
        public double Y
        {
            get { return m_Y; }
            set { m_Y = value; }
        }

        /// <summary>
        /// 离散点海拔高度，m
        /// </summary>
        double m_Elevation;
        /// <summary>
        /// 离散点海拔高度，m
        /// </summary>
        public double Elevation
        {
            get { return m_Elevation; }
            set { m_Elevation = value; }
        }
        /// <summary>
        /// 离散点标高，m
        /// </summary>
        double m_Height;
        /// <summary>
        /// 离散点标高，m
        /// </summary>
        public double Height
        {
            get { return m_Height; }
            set { m_Height = value; }
        }

        /// <summary>
        /// 离散点背景值   该字段暂时不使用
        /// </summary>
        double m_BackValue;

        public double BackValue
        {
            get { return m_BackValue; }
            set { m_BackValue = value; }
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }

    }


}
